<?php
include("config.php");
$gameid = $_GET['id'];
$query = mysql_query("SELECT * FROM demo WHERE demo_ID='$gameid'");
$result = mysql_fetch_assoc($query);

echo "<input type='hidden' id='gameid' value='" . $result['demo_ID'] . "' />";
if (!is_null($result['demo_URL'])) {
	echo "<input type='hidden' id='demoid' value='" . $result['demo_URL'] . "' />";
?>
<script type="text/javascript" src="http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject.js"></script>
<script type="text/javascript">		
	var name = document.getElementById("demoid").value;
	unityObject.embedUnity("unityPlayer", name, 600, 450);
</script>

<?php } ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/XGame_template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<script type="text/javascript">
function loadShoppingCart() {
	var xmlhttp;
	var gid = document.getElementById("gameid").value;
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  
	  xmlhttp.onreadystatechange=function()
	  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				if (xmlhttp.responseText=="unauthorized")
					window.location='Register.php';
				else
					alert("Added to cart");
			}
	  }
	xmlhttp.open("POST","add2.php",true);
	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	xmlhttp.send("addID=" + gid);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>XGame</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->

<!-- InstanceEndEditable -->
<link type="text/css" rel="stylesheet" href="CSS/css.css" />
</head>

<body>
<div id="container">

<div id="wrapper">

<div id="banner">
<!-- InstanceBeginEditable name="TopLink" -->
<?php
session_start();
if(!empty($_SESSION['login_user'])){
	$login = $_SESSION['login_user'];
	$q = "SELECT user_name FROM user where user_ID = '$login'";
	$rst=mysql_query($q);
	$data_fetch=mysql_fetch_array($rst);
?>
<ul class="topLink">
<li> Welcome, <a href="UserProfile.php"> <?php echo $data_fetch['user_name']; ?> </a> </li>
<li> <a href="Wishlist.php"> Wishlist </a> &nbsp; | &nbsp;<a href="userShoppingCart.php"> Cart </a> </li>
<li> <a href="Logout.php"> Logout </a> </li>
</ul>
<?php
	}
	else{
?>
<div class="welcome">
<p style="float:right; padding-right:10px"> Welcome: &nbsp; (
<a href="Register.php"> LOGIN</a> |
<a href="Register.php"> REGISTER </a>) </p>
</div>
<?php
	}
?>
<!-- InstanceEndEditable -->
<img src="Assets/XGame.png" alt="XGame" />
</div>

<div id="menu">
<ul class="nav">
<li> <span> <input type="text" placeholder="Search Keyword" name="Search Games" />
&nbsp; <input type="submit" name="Search" value="Search" /> </span>
</li>
<li> <a href="Home.php"> Home </a> </li>
<li> <a href="ListOfNews.php"> News </a> </li>
<li> <a href="Games.php"> Games </a> </li>
<li> <a href="FAQ.php"> FAQ </a> </li>
<li> <a href="ContactUs.php"> Contact Us </a> </li>
</ul>

</div>

<div id="main">
<!-- InstanceBeginEditable name="Main" -->
<table border="0" width="780px">
<tr>
<td width="210px">
<p align="center">
<?php
echo "<img src='display_photo.php?id=" . $result['demo_ID'] . "' alt='Games' width='200' height='180' style='border:1px solid #000; padding:5px'";
?>
</p>
<p align="center"> 
<button type='button' onclick='loadShoppingCart()'>Add to cart</button>
</p>
</td>
<td width="8px"> &nbsp; </td>
<td valign="top">
<h2><?php echo $result['demo_name']; ?></h2>
<p><?php echo $result['demo_long_desc']; ?></p>
<p>Price: <?php echo  "$" . $result['demo_price']; ?></p>
</td>
</tr>
<tr>
<td colspan="3" style="border-bottom:1px solid #666"> &nbsp; </td>
</tr>
</table>

<h2> DEMO </h2>
<?php
if (!is_null($result['demo_URL'])) {
	echo "<div id='unityPlayer'></div>";
}
else 
echo "<p><i> No demo available. </i> </p>";
?>

<!-- InstanceEndEditable -->
</div>

<div id="footer">
<p align="center"> &copy; &nbsp; 2012 XGame </p>
</div>

</div>

</div>

</body>
<!-- InstanceEnd --></html>
